package com.rchat.pocmini.activity.groupsselect;

import com.aso.common.http.delegate.HttpCallbackImpl;
import com.aso.common.http.utils.HttpUtils;
import com.rchat.pocmini.activity.groupsselect.view.GroupSelectBean;
import com.rchat.pocmini.global.HttpCodeGlobal;
import com.rchat.pocmini.global.HttpNodeGlobal;
import com.rchat.pocmini.global.RequestParam;
import com.rchat.pocmini.global.UrlsGlobal;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by itsdf07 on 2017/8/31.
 */

public class GroupsSelectorModelImpl implements GroupsSelectorContract.Model {
    @Override
    public void checkKeepGroups(String userName, ArrayList<GroupSelectBean> list, HttpCallbackImpl callback) {
        try {
            JSONArray groupIds = new JSONArray();
            for (GroupSelectBean bean : list) {
                groupIds.put(bean.getGroupId());
            }
            JSONObject root = RequestParam.buildGeneralParam(HttpCodeGlobal.REQ_CODE_1223);
            JSONObject data = new JSONObject();
            data.put(HttpNodeGlobal.NodeReqPlatform,RequestParam.REQUEST_PLATFORM);
            data.put(HttpNodeGlobal.NodeReqVersion, HttpCodeGlobal.getUrlVersion(HttpCodeGlobal.REQ_CODE_1223));
            data.put(HttpNodeGlobal.NodeReqEnterprise, RequestParam.REQUEST_ENTERPRISE);
            data.put("userName", userName);
            data.put("groupIds", groupIds);
            root.put("data", data);
            //body = {"code":1223,"data":{"userName":"111110000088","groupIds":["C20040","C20625","C20692","C20756","C20757"]}}
            String body = root.toString();
            HttpUtils.postAsyn(UrlsGlobal.getUrl(UrlsGlobal.RUL_UNVIP_EXPIRY), body, callback);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
